Ext.ns('Wlanauth.role');

Wlanauth.role.GridPanel = Ext.extend(Wlanauth.BaseGridPanel,{
	storeUrl:'role!list.action',
	userStatusType:'',
	constructor:function(cfg){
		Ext.apply(this,cfg);
		
		this.store = new Ext.data.JsonStore({
			url:this.storeUrl,
			totalProperty:'data',
			root:'rows',
			fields:['id','name','code','editable']
			
		});
		
		this.bbar = new Ext.PagingToolbar({
		    store:this.store,
		    displayInfo: true,
	        pageSize: this.pageSize,
	        displayInfo:true,
	     	displayMsg:'共{2}条记录',
	        emptyMsg:'没有记录'

	   });
		var sm = new Ext.grid.CheckboxSelectionModel();
		var config = {
			loadMask:true,
			border:false,
			store:this.store,
			sm:sm,
			cm:new Ext.grid.ColumnModel({
				columns:[new Ext.grid.RowNumberer(),sm,
				    {header:'编码',dataIndex:'code',width:120},
				    {header:'角色名称',dataIndex:'name',width:150,renderer:this.rolenameRender}
				]}),
			 viewConfig: {
	            forceFit: true
			 },
			 tbar:[{
				 text:'添加',
				 iconCls:'add',
				 handler:this.addObject,
				 hidden:!ZZExt.ApplicationContext.actionAccessable('wlanauth.role.add')
			 },'-',{
				 text:'修改',
				 iconCls:'edit',
				 handler:this.editObject,
				 scope:this,
				 hidden:!ZZExt.ApplicationContext.actionAccessable('wlanauth.role.edit')
			 },'-',{
				 text:'删除',
				 iconCls:'delete',
				 handler:this.deleteObject,
				 scope:this,
				 hidden:!ZZExt.ApplicationContext.actionAccessable('wlanauth.role.delete')
			 }]
		};
		
		Wlanauth.role.GridPanel.superclass.constructor.call(this,config);
		//this.fireEvent('autoload');
		this.on('rowdblclick',this.editObject,this);
	},
	rolenameRender:function(val,meta,record,row,col,store){
		var editable = record.get('editable');
		
		return !editable?'<font style="color:red">'+val+'</font>':val;
	},
	editObject:function(){
		var r = this.getSelectionModel().getSelected();
		if(!r){Ext.Msg.alert('提示','请选择一项');return;}
		
	},
	
	deleteObject:function(){
		var grid = this;
		var r = this.getSelectionModel().getSelected();
		if(!r){Ext.Msg.alert('提示','请选择一项');return;}
		if(!r.get('editable')){
			Ext.Msg.alert('提示','该角色不允许删除!');
			return ;
		}
		Ext.Msg.confirm('警告','<font style="color:red;font-weight:bold">您确定删除角色['+r.get('name')+']吗?',function(btn){
			if(btn=='yes'){
				Ext.Msg.wait('删除...');
				Ext.Ajax.request({
					url:'role!delete.action',
					params:{'entity.id':r.get('id')},
					success:function(response,opts){
						if(checkException(response)){
							Ext.Msg.alert('提示','删除成功');
							grid.getStore().reload();
						}
					}
				
				});
			} 
		});
		
	}
	
});

Ext.reg('wlanauth.role.gridpanel',Wlanauth.role.GridPanel);